home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / Aidan's Class Libraries / Resources.doc < prev   
Encoding:
Text File  |  1997-07-20  |  3.4 KB  |  81 lines  |  [TEXT/CWIE]

  1. Resources in ACL:
  2.  
  3. Resources are to be accessed through three means:
  4.  
  5. Resource files (a collection of resources)
  6. Resources (a collection of references to data chunks)
  7. Resource Accessors (these are the data chunks)
  8.  
  9. Since I'm basically putting more structure on a moderately structured content, I've got to
  10. decide how to represent these things in a vaguely structured way on disk.
  11.  
  12. Resource files are obvious.
  13.  
  14. There should only be a very loose binding between resources and what they access.  A typical
  15. situation should look like:
  16.  
  17. Build window:
  18.     TBaseWindow::TBaseWindow( TResource res ) {
  19.         TResource winResource= TResource( res, 'WnPR' );
  20.         Rect *boundsRect= (Rect*)TContentGenerator::Build( TResource( winResource, 'rect', 0 ) );
  21.         mWindow= ::NewWindow( boundsRect, &c, &c );
  22.         delete boundsRect;
  23.         mContent= (TLayoutLeaf*)TContentGenerator::Build( TResource( winResource, 'cont', 0 ) );
  24.     }
  25.     TBaseWindow *myWindow= new TBaseWindow( TResource( theResFile, 'AcWN', 128 ) );
  26.  
  27. To register your own class to be built from a resource, the interface might look like
  28.  
  29.     class MContentGenerator
  30.     {
  31.         virtual void *BuildContent( TResource )=0;
  32.     }
  33.  
  34.     class TMyGenerator:
  35.         public MContentGenerator
  36.     {
  37.         virtual void *BuildContent( TResource );
  38.     }
  39.  
  40.     void *TMyGenerator::BuildContent( TResource res )
  41.     {
  42.         return( (void*)new TMyKindOfLayout( res ) );
  43.     }
  44.  
  45.     void Init() {
  46.         //...Miscelanious initialization
  47.         TContentGenerator::AddSubtypeGenerator( new TMyGenerator(), kConicContentTypeCode );
  48.         //...other initialization
  49.     }
  50.  
  51. Some things should be obvious about my goals around now..
  52. First:  Resources should be lightweight.  They're thrown around the stack all the time, and I
  53.     don't want that to incur that much overhead.
  54. Second: They're very abstract.  Data is gotten from the resource through build functions about
  55.     which we know nothing.
  56. Third: They can be referenced hierarchically.  It's possible to get a reference to a resource
  57.     via a containing resource..  Strictly speaking, the resource is not contained but is rather
  58.     referenced, but the point is that it is a one step process to get a resource whose reference
  59.     is contained in another one.
  60.  
  61. That having been said, its probably time to describe the resource format.
  62.  
  63. ACLs resources are the same as MacOS resources, with the following definition of their content:
  64. The content is full of 64-bit values, of which the first 32 describe a type and the meaning of
  65. the second 32 varies based on the value of the first.  There are only two ways in which the
  66. first 32 bits can affect the interpretation of the second:
  67.  
  68. If the first 32-bits are cleared, the second set is interpreted as an integer.
  69. For any other value of the first 32-bits, they are interpreted as a resource reference, and
  70.     are interpreted as the type-code of the resource.  The second 32-bits are then interpreted
  71.     as the index of the referenced resource of this type.
  72.  
  73. There also has to be some sort of way for certain resource items (such as menus) to find another
  74. instance of a resource item (such as the thing that will respond to the menu).  This will be
  75. done in the same way that Apple Event Objects will be resolved..  Through some kind of selector.
  76. There will be two ways that the selector will work in the framework: index and string, both of
  77. which will be passed to an "Object Resolver" function.
  78.  
  79. For example, the "Close" menu item would be stored in a resource that contained two data chunks..
  80. The string and the resolver.  The resolver would reference 'AcWN' "Front" (for the frontmost
  81. window).